package net.zoneland.greenleaf.system.service;


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.zoneland.greenleaf.system.dao.Sys_holidayconfDao;
import net.zoneland.greenleaf.system.entity.Sys_holidayconf;

/**
 * SYS_HOLIDAYCONF[SYS_HOLIDAYCONF]表操作Serfice实现类

 * 类   名：Sys_holidayconfServiceImpl<br/>
 * 表   名：SYS_HOLIDAYCONFSERVICEIMPL<br/>
 * 注   释：节假日配置表<br/>
 * 作   者：GREENLEAF<br/>
 * 单   位：浙江兰德纵横网络技术有限公司<br/>
 * 日   期：2015-04-28 15:14:22
**/
@Service("sys_holidayconfService")
public class Sys_holidayconfServiceImpl implements Sys_holidayconfServiceI { 

	public static Logger logger = Logger.getLogger(Sys_holidayconfServiceImpl.class);

	/**
	 * 自动注入DAO对象
	**/
	@Autowired
	private Sys_holidayconfDao sys_holidayconfDao;

	/**
	 * 新增或者更新数据方法接口
	**/
	@Override
	public Sys_holidayconf addOrUpdate(Sys_holidayconf sys_holidayconf){
		try {
			if (sys_holidayconf == null) {
				logger.warn(Sys_holidayconf.class.getName() + "对象参数信息为Empty！");
				return null;
			}
			Map<String, Object> map = new HashMap<>();
			map.put("id", sys_holidayconf.getId());
			List<Sys_holidayconf> list  = sys_holidayconfDao.getList(map);
			if(list!=null &&list.size()>0){
				//说明 数据已经存在,直接更新数据
				sys_holidayconfDao.edit(sys_holidayconf);
				return sys_holidayconf;
			}else{
				//说明 数据目前不存在
				sys_holidayconf.setId( UUID.randomUUID() + "" );
				sys_holidayconfDao.add(sys_holidayconf);
				return sys_holidayconf;
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 新增数据方法实现
	**/
	@Override
	public boolean add(Sys_holidayconf sys_holidayconf){
		try {
			sys_holidayconfDao.add( sys_holidayconf );
			return true;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 更新数据方法实现
	**/
	@Override
	public boolean update(Sys_holidayconf sys_holidayconf){
		try {
			sys_holidayconfDao.edit( sys_holidayconf );
			return true;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 查询数据方法实现
	**/
	@Override
	public Sys_holidayconf get( Map<String, Object> map ) {
		try {
			return sys_holidayconfDao.get( map );
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 查询数据方法实现（列表）
	**/
	@Override
	public List<Sys_holidayconf> getList(Map<String, Object> map){ 
		List<Sys_holidayconf> list = null;
		try {
			list = sys_holidayconfDao.getList( map );
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return list;
	}
	
	/**
	 * 查询数据总数方法实现
	**/
	@Override
	public int getListCount(Map<String, Object> map) { 
		int count = 0;
		try {
			count = sys_holidayconfDao.getListCount( map );
		} catch (Exception e) {
				count = 0;
		}
		return count;
	}
	
	/**
	 * 数据删除方法实现
	**/
	@Override
	public boolean delete(Map<String, Object> map){ 
		boolean flag = false;
		try {
			sys_holidayconfDao.delete( map );
			flag = true;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return flag;
	}
	
}
